package com.juzi.wopu.service.impl;

import java.util.List;
import java.util.Map;

import com.juzi.wopu.domain.SysCode;
import com.juzi.wopu.query.SysCodeQuery;
import com.juzi.wopu.service.ISysCodeService;

public class SysCodeServiceImpl extends BaseServiceImpl<SysCode> implements ISysCodeService{

	@SuppressWarnings("unchecked")
	@Override
	public List<SysCode> find(SysCodeQuery query) {
		String hql="from SysCode t where 1=1 ";
		if(query.getiId()!=null){
			hql=hql+" and t.iId="+query.getiId();
		}
		
		if(query.getsName()!=null){
			hql=hql+" and t.sName like '%"+query.getsName()+"%'";
		}
		
		if(query.getiType()!=null && query.getiType()!=-1L){
			hql=hql+" and t.iType ="+query.getiType();
		}
		
		if(query.getiParentId()!=null && query.getiParentId()!=-1L){
			hql=hql+" and t.iParentId ="+query.getiParentId();
		}
		return BaseDao.findByhql(hql);
	}

	@Override
	public void getSysCodeMap(Map<Long, SysCode> map1, Map<String, SysCode> map2) {
		List<SysCode> list=BaseDao.getAll(SysCode.class);
		if(list!=null && list.size()>0){
			if(map1!=null && map2==null){
				for(SysCode sysCode:list){
					map1.put(sysCode.getiId(), sysCode);
				}
			}
			else if(map1==null && map2!=null){
				for(SysCode sysCode:list){
					map2.put(sysCode.getsName(), sysCode);
				}
			}
			else if(map1!=null && map2!=null){
				for(SysCode sysCode:list){
					map1.put(sysCode.getiId(), sysCode);
					map2.put(sysCode.getsName(), sysCode);
				}
			}
		}
	}
}